package club.justwill.single.model;


import club.justwill.single.helper.CoreHelper;

import java.util.Date;

public class SecurityToken {
	private String processName;

	private String channel = ServiceChannel.getChannelType(0);

	private String sessionId;

	private long operatorUserId;

	private int userType;

	private Date requestTime = new Date();

	public void generateToken(SessionState sessionState) {
		this.sessionId = sessionState.getSessionId();
		this.operatorUserId = sessionState.getUserId();
		this.userType = sessionState.getUserType();
		this.processName = sessionState.getUserName();
	}

	public void generatePcToken(SessionState sessionState) {
		this.sessionId = sessionState.getSessionId();
		this.operatorUserId = sessionState.getUserId();
		this.userType = sessionState.getUserType();
		this.channel = ServiceChannel.getChannelType(10);
		this.processName = sessionState.getUserName();
	}

	public void generateAndroidToken(SessionState sessionState) {
		this.sessionId = sessionState.getSessionId();
		this.operatorUserId = sessionState.getUserId();
		this.userType = sessionState.getUserType();
		this.channel = ServiceChannel.getChannelType(20);
		this.processName = sessionState.getUserName();
	}

	public void generateIosToken(SessionState sessionState) {
		this.sessionId = sessionState.getSessionId();
		this.operatorUserId = sessionState.getUserId();
		this.userType = sessionState.getUserType();
		this.channel = ServiceChannel.getChannelType(30);
		this.processName = sessionState.getUserName();
	}

	public SecurityToken(long userId) {
		setOperatorUserId(userId);
	}

	public boolean isMorePowerfulThan(int other) {
		return CoreHelper.isMorePowerfulThan(userType, other);
	}

	public boolean isSystemUser() {
		return CoreHelper.isSystemUser(userType);
	}

	public boolean isCustomer() {
		return CoreHelper.isCustomer(userType);
	}

	public boolean isSuperUser() {
		return CoreHelper.isSuperUser(userType);
	}

	public boolean isAdministrator() {
		return CoreHelper.isAdministrator(userType);
	}

	public boolean isAnonymousUser() {
		return CoreHelper.isAnonymousUser(userType);
	}

	public boolean isMoreThanConsumer() {
		return !CoreHelper.isConsumer(userType) && !CoreHelper.isAnonymousUser(userType);
	}
	//generated getters and setters

	public String getProcessName() {
		return processName;
	}

	public void setProcessName(String processName) {
		this.processName = processName;
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(int channel) {
		this.channel = ServiceChannel.getChannelType(channel);
	}

	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public long getOperatorUserId() {
		return operatorUserId;
	}

	public void setOperatorUserId(long operatorUserId) {
		this.operatorUserId = operatorUserId;
	}

	public int getUserType() {
		return userType;
	}

	public void setUserType(int userType) {
		this.userType = userType;
	}

	public Date getRequestTime() {
		return requestTime;
	}

	public void setRequestTime(Date requestTime) {
		this.requestTime = requestTime;
	}
}